<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>九宫格</title>
  <style>
    .container {
      width: 600px;
      height: 600px;
      background-color: red;
      /* 水平居中 */
      margin: 0 auto;
    }

    /* 直接子代 */
    .container>div {
      float: left;
      width: 190px;
      height: 190px;
      margin-left: 10px;
      margin-top: 10px;

      /* background-color: blue; */

    }

    /* 奇偶 */
    .container>div:nth-child(odd) {
      background-color: antiquewhite;
    }

    .container>div:nth-child(even) {
      background-color: gold;
    }

    .container>div:nth-child(3n+1) {
      margin-left: 0px;
    }
  </style>
</head>

<body>
  <div class="container">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </div>

</body>

</html>